// index.js
const api = require("../../utils/request");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods_info: {},
    goods_img: [],
  },
  by() {
    if (wx.getStorageSync('loginState')) {
      api.petEdit({
        header: {
          "Authorization": wx.getStorageSync('token')
        },
        data: {
          photos: this.data.goods_info.photos,
          title: this.data.goods_info.title,
          content: this.data.goods_info.content,
          name: "",
          type: "",
          sex: "",
          status: this.data.goods_info.status,
          extend: this.data.goods_info.extend,
          breed: "",
          price: this.data.goods_info.price
        }
      }).then(res => {
        wx.showToast({
          title: '添加成功',
          icon: "none"
        })
      })
    } else {
      wx.showToast({
        title: '未登录',
        icon: "none"
      })
    }
  },
  previewImage: function (e) {
    wx.previewImage({
      current: e.currentTarget.dataset.src,
      urls: this.data.goods_img
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    api.goodsGet({
      data: {
        id: e.id
      }
    }).then(res => {
      var photo = res.data.data.photos.split(",")
      this.setData({
        goods_info: res.data.data,
        goods_img: photo
      })

    })
  },
})